package edu.sctu.zhoumengxue.day201506.day20150602;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by user12 on 2015/6/7.
 */
public class CountTime {
    public String setTime(String string1,String string2) throws ParseException {

    SimpleDateFormat simple = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
    Date one;
    Date two;
    long day = 0;
    long hour = 0;
    long min = 0;
    long sec = 0;

    try{

        one = simple.parse(string1);
        two = simple.parse(string2);
        long time1 = one.getTime();
        long time2 = two.getTime();
        long lo;
        if(time1<time2){
            lo = time2-time1;

        }else {lo = time1-time2;
        }
        day = lo/(24*60*60*1000);
        hour = (lo/(60*60*1000)-day*24);
        min = ((lo/(60*1000))-day*24*60-hour*60);
        sec = (lo/1000-day*24*60*60-hour*60*60-min*60);
    }catch (ParseException e){
        e.printStackTrace();
    }

    return day+"天"+hour+"时"+min+"分"+sec+"秒";


}
}
